package com.spring.sunflower.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import com.spring.sunflower.R;

public class CircleProgressBar extends View {
  private static float MAX_PROGRESS = 100.0F;
  
  private int color;
  
  private float mAngle;
  
  private Context mContext;
  
  private Paint mPaint;
  
  private float mProgress = 0.0F;
  
  private int roundWidth = 10;
  
  static  {
  
  }
  
  public CircleProgressBar(Context paramContext) { this(paramContext, null); }
  
  public CircleProgressBar(Context paramContext, AttributeSet paramAttributeSet) { this(paramContext, paramAttributeSet, 0); }
  
  public CircleProgressBar(Context paramContext, AttributeSet paramAttributeSet, int paramInt) {
    super(paramContext, paramAttributeSet, paramInt);
    this.mContext = paramContext;
    init(paramAttributeSet, paramInt);
  }
  
  public void init(AttributeSet paramAttributeSet, int paramInt) {
    this.mPaint = new Paint();
    TypedArray typedArray = this.mContext.obtainStyledAttributes(paramAttributeSet, R.styleable.CircleProgressBar, paramInt, 0);
    boolean bool = typedArray.hasValue(0);
    paramInt = -1;
    if (bool)
      paramInt = typedArray.getInt(0, -1); 
    this.color = paramInt;
    typedArray.recycle();
  }
  
  protected void onDraw(Canvas paramCanvas) {
    super.onDraw(paramCanvas);
    int i = getWidth() / 2;
    this.mPaint.setColor(this.color);
    this.mPaint.setStyle(Paint.Style.STROKE);
    this.mPaint.setStrokeWidth(this.roundWidth);
    this.mPaint.setAntiAlias(true);
    i = this.roundWidth;
    paramCanvas.drawArc(new RectF(i, i, (getWidth() - this.roundWidth), (getWidth() - this.roundWidth)), -90.0F, this.mAngle, false, this.mPaint);
  }
  
  public void setColor(int paramInt) { this.color = paramInt; }
  
  public void setProgress(float paramFloat) {
    float f = MAX_PROGRESS;
    if (paramFloat > f) {
      this.mProgress = f;
      this.mAngle = 360.0F;
    } else {
      this.mProgress = paramFloat;
      this.mAngle = paramFloat * 360.0F / f;
    } 
    invalidate();
  }
}
